//
//  OPMainTabBarController.m
//  NewWorld
//
//  Created by 飞奔的羊 on 16/4/27.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "OPMainTabBarController.h"
#import "OPMainNavigationController.h"
#import "OPCarFoundTableViewController.h"
#import "OPZJCarSourceTableViewController.h"
#import "OPMineTableViewController.h"

#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
@interface OPMainTabBarController ()

@end

@implementation OPMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addChildViewControlls];
}

/**
 *  添加控制器
 */

- (void)addChildViewControlls
{
   OPZJCarSourceTableViewController  *carSource = [[OPZJCarSourceTableViewController alloc]init];
    [self addOneChlildVc:carSource title:@"车源" imageName:@"456" selectedImageName:@"456SE"];
    
     OPCarFoundTableViewController *carFound = [[OPCarFoundTableViewController alloc] init];
    [self addOneChlildVc:carFound title:@"寻车" imageName:@"123" selectedImageName:@"123SE"];
    
    OPMineTableViewController *mine = [[OPMineTableViewController alloc] init];
    [self addOneChlildVc:mine title:@"我的" imageName:@"789" selectedImageName:@"789SE"];
    



}
- (void)addOneChlildVc:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{
    // 设置标题
    childVc.title = title;
    
    
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    
    selectedTextAttrs[UITextAttributeTextColor] = [UIColor colorWithRed:18/255.0 green:118/255.0 blue:218/255.0 alpha:1.0];
    [childVc.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
#pragma clang diagnostic pop
    
    // 设置图标
    childVc.tabBarItem.image = [UIImage imageNamed:imageName];
    
    // 设置选中的图标
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    if (iOS7) {
        // 声明这张图片用原图(不渲染)
        selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    childVc.tabBarItem.selectedImage = selectedImage;
    
    // 添加为tabbar控制器的子控制器
    OPMainNavigationController *nav = [[OPMainNavigationController alloc] initWithRootViewController:childVc];
    
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
